/*****************************************************************
 MYD Engine v0.1

 file: myd_animation.cpp
 created: 06/07/09
*****************************************************************/

#include "myd_animation.h"
#include "entities/myd_sprite.h"

using namespace myd;

Animation::Animation ()
:
isPlaying(false)
{
}

Animation::~Animation ()
{
}

void Animation::addFrame(unsigned int xoff, unsigned int yoff, 
						 unsigned int width, unsigned int height)
{
	Frame newFrame;
	newFrame.frOffsetX = xoff;
	newFrame.frOffsetY = yoff;
	newFrame.frWidth   = width;
	newFrame.frHeight  = height;

	framesList.push_back(newFrame);	
}

unsigned int Animation::calculateFrame(float fAppTime)
{
	float fAnimTime = fAppTime - fAppInitTime; 

	if(looped)
	{
		float fPassTime = fmod(fAnimTime, speed);

		return (fPassTime * frameCount)/speed;
	}
	else
	{
		if(fAnimTime > speed)
		{
			return frameCount - 1;
		}

		return (fAnimTime * frameCount)/speed;
	}
}